/*
 * Copyright (C) 2015 yixun All Rights Reserved.
 * 
 * EstateTypeEnum.java
 */
package com.yixun.qfbao.xf.model.enums;

import com.yixun.common.utils.EnumUtil;
import com.yixun.qfbao.model.enums.FloorEnum;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * [文件名称]<br>
 * PremisesDynamic.java<br>
 * <br>
 * [文件描述]<br>
 * 楼盘动态 pojo bean<br>
 * <br>
 * [修改记录]<br>
 * 2015-10-14 15:34:13 创建 陶俊代码生成器<br>
 * 
 * @author 陶俊代码生成器
 * @version 1.00
 */
public enum EstateTypeEnum implements Serializable {
	UNLIMITED("-1", "不限", null),
	type_0("0", "住宅", null),
	type_1("1", "商住", null),
	type_2("2", "商铺", null),
	type_3("3", "网点", null),
	type_12("12", "公寓", null),
	type_4("4","写字楼", null),
	type_5("5", "厂房", null),
	type_6("6", "写厂", null),
	type_7("7", "铺厂", null),
	type_8("8", "仓库",null),
	type_9("9", "地皮", null),
	type_10("10", "车位", null),
	type_11("11", "其它", null),
	;

	private final String no;
	private final String des;
	private final Enum parent;

	public final static String REG = ",";

	static {
		EnumUtil.ENUMS_TO_VIEW.put("estate_type", EstateTypeEnum.values());
	}

	/**
	 * 私有构造函数
	 * 
	 * @param no
	 * @param des
	 */
	EstateTypeEnum(String no, String des, Enum parent) {
		this.no = no;
		this.des = des;
		this.parent = parent;
	}

	/**
	 * @return Returns the no.
	 */
	public String getNo() {
		return no;
	}

	/**
	 * @return Returns the des.
	 */
	public String getDes() {
		return des;
	}

	/**
	 * @return Returns the parent.
	 */
	public Enum getParent() {
		return parent;
	}

	/**
	 * 通过枚举<code>des</code>获得枚举
	 * 
	 * @param des
	 * @return
	 */
	public static EstateTypeEnum getByDescription(String des) {
		if (StringUtils.isBlank(des)) {
			return null;
		}
		for (EstateTypeEnum menum : values()) {
			if (menum.getDes().equals(des)) {
				return menum;
			}
		}
		return null;
	}

	public static EstateTypeEnum getByNo(String no) {
		if (StringUtils.isBlank(no)) {
			return null;
		}
		for (EstateTypeEnum menum : values()) {
			if (menum.getNo().equals(no)) {
				return menum;
			}
		}
		return null;
	}

	public static String getByIds(String ids) {
		List<String> list = new ArrayList<>();
		if (!StringUtils.isEmpty(ids)) {
			List<String> idsStr = Arrays.asList(ids.split(REG));
			idsStr.forEach(item -> {
				EstateTypeEnum type = getByNo(item);
				if (type != null) {
					list.add(type.getDes());
				}
			});
			return StringUtils.join(list, REG);
		}
		return null;
	}

	public static String getNameByCode(String code) {
		if (!StringUtils.isEmpty(code)) {
			EstateTypeEnum anEnum = getByNo(code);
			if (anEnum != null) {
				return anEnum.getDes();
			} else {
				return null;
			}
		}
		return null;
	}
}
